<?php
namespace app\admin\controller;
use think\console\Input;

use think\Request;

use think\Controller;
use think\Db;
class Info extends Controller
{
   public function info()
   {
   	$list=Db::name("jf_info")
   	         ->paginate(2);
            
            $page = $list->render();

            $this->assign('list',$list);
            $this->assign('page', $page);
      return $this->fetch();
   }
   
   
   public function stu_add()
   {
   	  $request=Request::instance();
   	  if($request->has('sub','post'))
   	  {
   	    
   	     $i_number=$request->post('i_number');
   	     $i_class=$request->post('i_class');
   	     $i_bteam=$request->post('i_bteam');
   	     $i_steam=$request->post('i_steam');
   	     $i_job=$request->post('i_job');
   	     $data=[
   	           'i_number'=>$i_number,
   	           'i_class'=>$i_class,   	           
   	           'i_bteam'=>$i_bteam,
	   	       'i_steam'=>$i_steam,
	   	       'i_job'=>$i_job,	           
   	     ];
   	   $result=Db::table('jf_info')->insert($data);
   	   if($result)
   	   {
   	      $this->success('新增成功','Info/info');
   	   }
   	   else 
   	   {
   	      $this->error('新增失败');
   	   }
   	  }
   	  else 
   	  {
   	     $i_id=input('?param.i_id');
   	     $jf_info=Db::table('jf_info')->where('i_id',$i_id)->find();
   	     return $this->fetch('stu_add',[
   	                             'jf_info'=>$jf_info
   	         ]);
   	  }
      //return $this->fetch(); 
   }
   public function stu_update()
   {
  	$request=Request::instance();
  	if ($request->has("sub","post"))
  	{
  		 $i_id=$request->post("i_id");
	     $i_number=$request->post('i_number');
   	     $i_class=$request->post('i_class');
   	     $i_bteam=$request->post('i_bteam');
   	     $i_steam=$request->post('i_steam');
   	     $i_job=$request->post('i_job');
   	     $data=[
   	           'i_id'=>$i_id,
   	           'i_number'=>$i_number,
   	           'i_class'=>$i_class,   	           
   	           'i_bteam'=>$i_bteam,
	   	       'i_steam'=>$i_steam,
	   	       'i_job'=>$i_job,	           
   	     ];   
	     $result=Db::table("jf_info")
		         ->update($data);
	  	if($result)
		  {$this->success("修改成功","Info/info");}
	    else 
		  {$this->error("修改失败");}
	  	}
  	else 
  	{
	  	$i_id=$request->param("i_id");
	  	$data=['i_id'=>$i_id];  
		$list=Db::name("jf_info")
			  ->where('i_id',$i_id)
	          ->find();
	     return $this->fetch('stu_update',[
               'list'=>$list,
       ]);        
  	}
   }
   public function stu_delete()
   {
      $request=Request::instance();
      $i_id=$request->param('i_id');
      $data=['i_id'=>$i_id];
      $result=Db::table('jf_info')->delete($data);
      if($result)
      {
      	
        $this->success('删除成功','Info/info');  
      }
      else 
      {
        $this->error('删除失败');
      }
      
   }
}
